﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing.Drawing2D;

namespace 易容酒店管理系统
{
    public partial class main : Form
    {
        public main()
        {
            InitializeComponent();
        }

        private void main_Load(object sender, EventArgs e)
        {
            Log_In log_in = new Log_In();
            log_in.ShowDialog();
            if (Method.Bool)
            {
                //
            }
            else { this.Close(); }
            label1.Text = Method.UserName;
            //加载功能界面
           
            Main_function newMain_function = new Main_function();
            newMain_function.TopLevel = false;
            panel1.Controls.Clear();
            panel1.Controls.Add(newMain_function);
            newMain_function.Show();


            SetDouble(this);
            SetDouble(panel1);
            Method.frm = this;

            Method.frm.button1.Visible = false;
            Method.frm.button2.Visible = false;
            Method.frm.button3.Visible = false;
            Method.frm.button4.Visible = false;
            Method.frm.button5.Visible = false;

            //palFunctionOne.BackColor = Color.FromArgb(254, 133, 77);
            //palFunctionTwo.BackColor = Color.FromArgb(85, 86, 86);
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);//绘制阴影
        }
        #region 绘制阴影
        private const int CS_DropSHADOW = 0x20000;
        private const int GCL_STYLE = (-26);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);
        #endregion
        #region 窗体移动
        private Point mouse_offset;//获取窗体当前X，Y的坐标
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            mouse_offset = new Point(-e.X, -e.Y);//获取移动后的坐标
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)//判断窗体位置是否发生了移动
            {
                Point mousePos = Control.MousePosition;             //更改窗体当前的X，Y坐标
                mousePos.Offset(mouse_offset.X, mouse_offset.Y);
                Location = mousePos;
            }
        }
        #endregion
        #region Min、Max
        private void picMin_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void picClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
        #region 员工头像
        private void StaffImage_Paint(object sender, PaintEventArgs e)
        {

            GraphicsPath gp = new GraphicsPath();
            gp.AddEllipse(StaffImage.ClientRectangle);
            Region region = new Region(gp);
            StaffImage.Region = region;
            gp.Dispose();
            region.Dispose();
        }
        #endregion
        #region 防止闪屏
        public static void SetDouble(Control cc)
        {

            cc.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance |
                         System.Reflection.BindingFlags.NonPublic).SetValue(cc, true, null);

        }
        protected override void WndProc(ref Message m)
        {

            if (m.Msg == 0x0014) // 禁掉清除背景消息  

                return;

            base.WndProc(ref m);

        }
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }  
        #endregion
        #region 登录
        private void picLog_in_Click(object sender, EventArgs e)
        {
            Log_In login = new Log_In();
            login.ShowDialog();
            if (Method.Bool)
            {
                label1.Text = Method.UserName;

                Main_function newMain_function = new Main_function();
                newMain_function.TopLevel = false;
                panel1.Controls.Clear();
                panel1.Controls.Add(newMain_function);
                newMain_function.Show();
                SetDouble(this);
                SetDouble(panel1);
                Method.frm = this;
            }
            else 
            {
                //
            }
        }
        #endregion

        private void picShift_Click(object sender, EventArgs e)
        {
            Shift newShift = new Shift();
            newShift.ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Check newChek = new Check();
            newChek.ShowDialog();
        }
        //返回首页
        private void button5_Click(object sender, EventArgs e)
        {
            Main_function newMain_function = new Main_function();
            newMain_function.TopLevel = false;
            panel1.Controls.Clear();
            panel1.Controls.Add(newMain_function);
            newMain_function.Show();

            Method.frm.button1.Visible = false;
            Method.frm.button2.Visible = false;
            Method.frm.button3.Visible = false;
            Method.frm.button4.Visible = false;
            Method.frm.button5.Visible = false;
        }
        //换房
        private void button2_Click(object sender, EventArgs e)
        {
            Trade newTrade = new Trade();
            newTrade.ShowDialog();
        }
        //预定
        private void button1_Click(object sender, EventArgs e)
        {
            Reserve newReserve = new Reserve();
            newReserve.ShowDialog();
        }
        //退房
        private void button4_Click(object sender, EventArgs e)
        {
            check_out newcheck_out = new check_out();
            newcheck_out.Show();
        }
    }

}
